import { Component, OnInit, ViewChild } from '@angular/core';
import { MemberService } from '../member.server';
import { Router } from '@angular/router';
import { LayoutRourteStatus } from 'src/app/model/status';
import { MessageService, HUAN_ZHE_A, HUAN_ZHE_LIST } from 'src/app/core/service';
import { FormGroup, FormBuilder } from '@angular/forms';
import { TradeType, TradeTypes, formatDateGlob, ksData } from '../pipe-member/pipe.member';
import { cellConfig, TableComponent } from 'src/app/components/table-basic/table-basic';
import { NzMessageService, NzNotificationService } from 'ng-zorro-antd';

@Component({
    templateUrl: './member-center-yshtg-list.component.html',
    styleUrls: ['./member-center-yshtg-list.component.scss']
})
export class YshtgListComponent implements OnInit {
    validateForm: FormGroup;
    tradeTypes: TradeType[] = TradeTypes;

    private _layoutRourteStatus: LayoutRourteStatus = {
        url: '/member/center/transactionListPage',
        isHiddeBreadcrumb: true,
        breadcrumbs: [{ tragetTitle: '已审核处方单' }]
    };
    visible: boolean = false;
    isSpinning: boolean = false;
    isOver: boolean = false;
    dataFilter: any = {
        name: null,
        key: null
    };

    private _msgList: Array<any>;
    private _data: Array<any> = [];
    private _dataY: Array<any> = [];
    private ksSel: string[] = [];
    private nodes: any[] = ksData;
    private _totalMap: any;
    itemDataConfig: ItemDataConfig

    private _config: Array<cellConfig> = [
        {
            name: '操作',
            class: 'table-w-10-huanHang',
            key: 'cz',
            labels: [
                {
                    name: '查看',
                    type: 'click'

                }
            ]
        }, {
            name: '处方号',
            key: 'cfhm'
        }, {
            name: '科室',
            key: 'ks'
        }, {
            name: '开方时间',
            key: 'kfsj',
        }, {
            name: '就诊卡号',
            key: 'jzkh',
        }, {
            name: '原处方号码',
            key: 'ycfhm'
        }, {
            name: '类型',
            key: 'lx'
        }, {
            name: '医生',
            key: 'ys'
        }
    ];
    private _configY: Array<cellConfig> = [
        {
            name: '药品编码',
            key: 'ypbm',
            class: 'table-w-10-huanHang'
        },
        {
            name: '名称',
            class: 'table-w-10-huanHang',
            key: 'mc'
        },
        {
            name: '规格',
            class: 'table-w-10-huanHang',
            key: 'gg'
        },
        {
            name: '包装规格',
            class: 'table-w-10-huanHang',
            key: 'bzgg'
        },
        {
            name: '生产企业',
            class: 'table-w-10-huanHang',
            key: 'scqy'
        },
        {
            name: '开方数量',
            class: 'table-w-10-huanHang',
            key: 'kfsl'
        }
    ];

    private _page: any = {
        pageNo: 1,
        pages: 0,
        totalCount: 0
    };
    private isshow = false;
    ngOnInit() {
        this.msg.sendLayoutRourteStatus(this._layoutRourteStatus);
        this.resetForm();
        this.loadList('商户提现列表');

    }
    onKSChange($event: string[]): void {
        $event.length > 0 ? this.dataFilter.name = $event[0] : this.dataFilter.name = '';
        this.filter(this.dataFilter.name, 'ks')
    }


    resetForm(): void {
        this.validateForm = this.fb.group({
            status: ['All'],
            duration: [[]],
            outTradeNo: [null],
            ksSel: [this.ksSel]
        });
        this._page = {
            pageNo: 1,
            pages: 1,
            totalCount: 10
        };
    }
    /**
     * onDtl 查看详情
     */
    private seltTdata: any;
    private dtlData: any;
    // tslint:disable-next-line:member-ordering
    private isShow: boolean = false;
    public onDtl(e): void {
        this.isShow = e['fxyy'];
        this.dtlData = e;
        this.visible = true;
        this.seltTdata = e;

    }
    closeBH() {
        this.visible = false;
    }
    public close(name: string, template): void {
    }
    /**
     * cancelTransfer 取消申请
     */
    public cancelTransfer(e): void {
        this.isSpinning = true;
        this.time();
    }
    public time(): void {
        setTimeout(() => {
            this.isOver = true;
        }, 600);
        setTimeout(() => {
        }, 800);
    }

    public onListClick(e): void {
    }
    public onSearch(type: string): void {
        this._page.pageNo = 1;
        if (type === 'reset') {
            this.resetForm();
        }
        this.loadList('商户提现列表');
    }


    async loadList(url) {
        // HUAN_ZHE_A
        this._data = this._fristData = HUAN_ZHE_LIST;
    }

    public successListOk(data, url): void {
    }
    searchAddress: string;
    filter(searchAddress: string, key: string): void {
        this.searchAddress = searchAddress;
        this.search(key);
    }
    private _fristData: Array<any>;
    private gdata: Array<any>;
    search(key: string): void {
        this._data = this._fristData;
        /** filter data **/
        const filterFunc = (item: ItemDataConfig) =>
            (this.searchAddress ? item[key].indexOf(this.searchAddress) !== -1 : true);

        const data = this._data.filter(item => filterFunc(item));
        this._data = data;
    }

    constructor(
        private memberServer: MemberService,
        private router: Router,
        private msg: MessageService,
        private message: NzMessageService,
        private notification: NzNotificationService,
        private fb: FormBuilder
    ) { }
}


export interface ItemDataConfig {
    ks: string,
    bzgg: string,
    gg: string,
    kfsl: string,
    mc: string,
    scqy: string,
    ypbm: string
}
